import InteractiveBase from "../../LevelCommon/InteractiveBase";
import LevelBaseControl from "../../LevelCommon/LevelBaseControl";
import { GamePropData } from "../../Data/GamePropData";
import Sound from "../../../constant/SoundNameConstant";

export default class Fire extends InteractiveBase {
    
    /** 点燃需要的物品id*/
    public fireNeedObjId: number;
    /** 可以燃烧的道具*/
    public canFireObjId: number;
    /** 火堆是否已经点燃*/
    private haveFired: boolean = false;
    /** 关卡*/
    private curLevel: LevelBaseControl;
    /** 火焰特效*/
    private fireEffect: Laya.Sprite3D;

    onStart() {
        this.curLevel = window.gameFacade.LevelMng.GetCurLevelControl();
        this.fireEffect = this.owner.getChildByName("fireEff") as Laya.Sprite3D;;
    }

    protected InteractiveLogic(): boolean {
        let curSelect: GamePropData = this.curLevel.CurSelectProp;
        /** 已经点燃了 判断有没有可以燃烧的道具*/
        if (this.haveFired) {
            /** 如果选中了可以点燃的物体*/
            if (curSelect != null && curSelect.id == this.canFireObjId) {
                /** 使用道具*/
                this.curLevel.UseCurProp();
                this.CallToLevel();
            }
        }
        /** 没有点燃判断有没有可以点火的道具*/
        else {
            /** 如果选中了可以点燃的物体*/
            if (curSelect != null && curSelect.id == this.fireNeedObjId) {
                /** 点燃*/
                this.haveFired = true;
                this.fireEffect.active = true;
                window.gameFacade.SoundMng.playSound(Sound.soundClipArr.FIRE);
                this.curLevel.UseCurProp();
            }
        }
        return true;
    }
}